# 接口测试

import requests
import json


# reg = requests.post('http://127.0.0.1:5000/users/reg',{'username':'z1111s','password':'123','mobile':13131563903})
# print(reg.text)


class TestInteface:
    def __init__(self, method, url, data=''):
        if method == 'post':
            self.res = requests.post(url, data)
        else:
            self.res = requests.get(url)

    # 把返回的结果转成json
    def get_comment(self):
        return self.res.json()


# 测试登录
# 先通过手机号获取验证码
testinterface = TestInteface('post', 'http://localhost:5000/users/sendsms', {'mobile': 13013286056})
res = testinterface.get_comment()

if res['code'] == 200:
    code = res['smscode']
    print(code)
    interface = TestInteface('post', 'http://localhost:5000/users/mdl', {'mobile': 13013286056, 'code': code})
    res = interface.get_comment()
    print(res)

